package com.meituan.mapper;

import com.meituan.model.EvaluateEntity;
import com.meituan.provider.EvaluateProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface EvaluateMapper {
    @Select("select * from evaluate where shop_id = #{shopId}")
    @Results({
            @Result(property = "orderId",column = "order_id"),
            @Result(property = "evaluationId",column = "evaluation_id"),
            @Result(property = "userId",column = "user_id"),
            @Result(property = "orderDetailEntityList",column = "order_id",
                    many = @Many(select = "com.meituan.mapper.OrderDetailMapper.findById",fetchType = FetchType.EAGER)),
            @Result(property = "userEntity",column = "user_id",
            one = @One(select ="com.meituan.mapper.UserMapper.findById",fetchType = FetchType.EAGER)),
            @Result(property = "replyEntity",column = "evaluation_id",
            one = @One(select ="com.meituan.mapper.ReplyMapper.findByEvaluationId",fetchType = FetchType.EAGER))
    })
    List<EvaluateEntity> findByShopId(String shopId);

    @InsertProvider(type= EvaluateProvider.class,method = "insertEvaluate")
    Integer insert(EvaluateEntity evaluateEntity);

    @Update("update evaluate set reply_id = #{replyId} where evaluation_id = #{evaluationId}")
    Integer updateReply(@Param("replyId")String replyId,@Param("evaluationId") String evaluationId);

}
